{extend name="app/admin/view/base.html"/}
{block name="resources"}
{/block}
{block name="main"}

{if condition="$list.data.pintuan_info"}
	<div class="ns-detail-card ns-tips">
		<div class="ns-detail-img">
			<img layer-src src="{:img(explode(',', $list.data.pintuan_info.goods_image)[0])}"/>
		</div>
			
		<div class="ns-detail-con">
			<p class="ns-detail-line">
				<span class="ns-goods-name">{$list.data.pintuan_info.goods_name}</span>
				<span class="ns-text-color">（活动名称：{$list.data.pintuan_info.pintuan_name}）</span>
			</p>
			<p class="ns-detail-line">
				<span class="ns-text-color">{if condition="$list.data.pintuan_info.status == 0"}未开始{/if}{if condition="$list.data.pintuan_info.status ==1"}进行中{/if}
				{if condition="$list.data.pintuan_info.status == 2"}已结束{/if}
				{if condition="$list.data.pintuan_info.status == 3"}已失效{/if}</span>
				<span class="ns-text-color">（{$list.data.pintuan_info.pintuan_num}人团）</span>
			</p>
			<p class="ns-detail-line">限 {$list.data.pintuan_info.buy_num}件/人</p>
			<p class="ns-detail-line">活动时间：{:date('Y-m-d H:i:s', $list.data.pintuan_info.start_time)} — {:date('Y-m-d H:i:s', $list.data.pintuan_info.end_time)}</p>
			<p class="ns-detail-line">
				<span class="ns-inline-span">是否是虚拟商品：{$list.data.pintuan_info.is_virtual_goods == 0 ? '否' : '是'}</span>
				<span class="ns-inline-span">是否是单独购买：{$list.data.pintuan_info.is_single_buy == 0 ? '否' : '是'}</span>
				<span class="ns-inline-span">是否是虚拟成团：{$list.data.pintuan_info.is_virtual_buy == 0 ? '否' : '是'}</span>
				<span class="ns-inline-span">是否有团长优惠：{$list.data.pintuan_info.is_promotion == 0 ? '否' : '是'}</span>
			</p>
		</div>
	</div>
{/if}


<div class="layui-tab ns-table-tab" lay-filter="status">
	<ul class="layui-tab-title">
		<li class="layui-this" data-status="">全部</li>
		<li data-status="3">拼团成功</li>
		<li data-status="2">组团中</li>
		<li data-status="1">拼团失败</li>
	</ul>
	
	<div class="layui-tab-content">
		<!-- 列表 -->
		<table id="team_list" lay-filter="team_list"></table>
	</div>
</div>

<!-- 列表 -->
<!-- <table id="" lay-filter="team_list"></table> -->

<!-- 商品 -->
<script type="text/html" id="goods">
	<div class="ns-table-tuwen-box">
		<div class="ns-img-box">
			<img layer-src src="{{ns.img(d.goods_image.split(',')[0])}}"/>
		</div>
		<div class="ns-font-box">
			<a href="javascript:;" class="ns-multi-line-hiding ns-text-color">{{d.goods_name}}</a>
		</div>
	</div>
</script>

<!-- 状态 -->
<script type="text/html" id="status">
	{{#  if(d.status == 1){  }}
	拼团失败
	{{#  }else if(d.status == 2){  }}
	组团中
	{{#  }else if(d.status == 3){  }}
	拼团成功
	{{#  }  }}
</script>

<!-- 操作 -->
<script type="text/html" id="action">
	<div class="ns-table-btn">
		<a class="layui-btn" lay-event="check">查看</a>
	</div>
</script>
{/block}

{block name="script"}
<script>
	var url = location.search; //获取url中"?"符后的字串
	if (url.indexOf("?") != -1) { //判断是否有参数
		var str = url.substr(1); //从第一个字符开始 因为第0个是?号 获取所有除问号的所有符串
		strs = str.split("="); //用等号进行分隔 （因为知道只有一个参数 所以直接用等号进分隔 如果有多个参数 要用&号分隔 再用等号进行分隔）
		if (strs[1] != '') {
			$(".layui-collapse").removeClass("layui-hide");
		}
	}

	layui.use(['form', 'element'], function() {
		var table,
			form = layui.form,
			element = layui.element;
		form.render();

		table = new Table({
			elem: '#team_list',
			url: ns.url("pintuan://admin/pintuan/group"),
			parseData: function(res) { //res 即为原始返回的数据
				return {
					"code": res.code, //解析接口状态
					"msg": res.message, //解析提示文本
					"data": res.data.list.list, //解析数据列表
					"count": res.data.list.count
				};
			},
			cols: [
				[{
					field: 'group_id',
					title: '编号',
					unresize: 'false',
					width: '5%',
				}, {
					title: '拼团商品',
					unresize: 'false',
					width: '20%',
					templet: '#goods'
				}, {
					title: '开团时间',
					unresize: 'false',
					width: '15%',
					templet: function(data) {
						var create_time = ns.time_to_date(data.create_time);
						return create_time;
					}
				}, {
					title: '结束时间',
					unresize: 'false',
					width: '15%',
					templet: function(data) {
						return ns.time_to_date(data.end_time);
					}
				}, {
					title: '差几人成团',
					unresize: 'false',
					width: '15%',
					templet: function(data) {
						return data.pintuan_num - data.pintuan_count;
					}
				}, {
					title: '拼团状态',
					unresize: 'false',
					width: '15%',
					templet: '#status'
				}, {
					title: '操作',
					toolbar: '#action',
					unresize: 'false',
					width: '15%'
				}]
			],

		});
		
		//监听Tab切换
		element.on('tab(status)', function(data) {
			var status = $(this).attr("data-status");
			table.reload({
				page: {
					curr: 1
				},
				where: {
					'status': status
				}
			});
		});
		
		/**
		 * 监听工具栏操作
		 */
		table.tool(function(obj) {
			var data = obj.data;
			switch (obj.event) {
				case 'check': //查看
					location.href = ns.url("pintuan://admin/pintuan/grouporder?group_id=" + data.group_id);
					break;
			}
		});
	});
</script>
{/block}